package thread;

/**
 * @description: 单例模式，懒汉式
 * @author: apple
 * @date:  2021/11/28 3:32 下午
 * @version 1.0
 **/
public class SimpleTest {

    public static void main(String[] args) {

    }
}

class Bank {

    private Bank(){}

    private static Bank b = null;

    public static Bank getInstance() {
        // 效率稍低
        synchronized (Bank.class) {
            if (b == null) {
                b = new Bank();
            }
            return b;
        }
    }

    public static Bank getInstance2() {
        // 效率最高
        if(b == null) {
            synchronized (Bank.class) {
                if (b == null) {
                    b = new Bank();
                }
            }
        }
        return b;
    }

    public static Bank getInstance3() {
        // 效率最高
        if (b != null) {
            return  b;
        }
        synchronized (Bank.class) {
            if (b == null) {
                b = new Bank();
            }
            return b;
        }
    }


}
